package com.system.connect.springboot_flowers.controller;

import com.system.connect.springboot_flowers.entity.Announcements;
import com.system.connect.springboot_flowers.service.IAnnouncementsService;
import com.system.connect.springboot_flowers.utils.R;
import com.system.connect.springboot_flowers.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 公告表 前端控制器
 * </p>
 *
 * @author yang
 * @since 2025-01-13
 */
@RestController
@RequestMapping("/api/announcements")
public class AnnouncementsController {

    @Autowired
    private IAnnouncementsService announcementsService;

    /**
     * 新建公告
     */
    @PostMapping
    public R create(@RequestBody Announcements announcements) {
        announcements.setUserId(Integer.valueOf(TokenUtils.getUser()));
        announcementsService.save(announcements);
        return R.success("新建公告成功");
    }

    /**
     * 查询所有公告
     * @return
     */
    @GetMapping
    public R getCoupons() {
        return R.success(announcementsService.list());
    }

}
